package com.example.projectmanagement.model.study;

import com.example.projectmanagement.model.User;
import com.fasterxml.jackson.annotation.JsonIgnore;
import jakarta.persistence.*;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.AllArgsConstructor;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
import java.time.LocalDateTime;
import java.util.List;

@Entity
@Table(name = "study_course")
@Data
@NoArgsConstructor
@AllArgsConstructor
@EntityListeners(AuditingEntityListener.class)
public class Course {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    @Column(nullable = false)
    private String title;

    @Column(length = 1000)
    private String description;

    @Column(name = "cover_image")
    private String coverImage;

    @Column(name = "difficulty_level")
    private String difficultyLevel; // 初级/中级/高级

    @Column(name = "estimated_duration")
    private Integer estimatedDuration; // 预计学习时长（分钟）

    @Column(name = "category")
    private String category; // 分类

    @Column(name = "subcategory")
    private String subcategory; // 子分类

    @ElementCollection
    @CollectionTable(name = "course_tags", joinColumns = @JoinColumn(name = "course_id"))
    @Column(name = "tag")
    @JsonIgnore
    private List<String> tags; // 标签

    @Column(name = "status")
    private String status; // 状态：待审核/已上架/已下架

    @ManyToOne
    @JoinColumn(name = "creator_id")
    private User creator;

    @CreatedDate
    @Column(name = "create_time", updatable = false)
    private LocalDateTime createTime;

    @LastModifiedDate
    @Column(name = "update_time")
    private LocalDateTime updateTime;

    @Column(name = "publish_time")
    private LocalDateTime publishTime;
}